/**
 * Created By xiyuan
 * Author server@xiyuan.name (惜缘叛逆)
 * DateTime 2020/9/1 2:23 PM
 * Describe javascript功能描述
 * MIT License http://www.opensource.org/licenses/mit-license.php
 */

const readline = require('readline');
const fs = require('fs');

export function readLine(path, callback, end) {
	// 创建文件流
	const readStream = fs.createReadStream(path);
	// 创建逐行读取接口
	const rl = readline.createInterface({
		input: readStream
	});
	
	// 是否停止标示
	let isClose = false;
	// 监听逐行读取
	rl.on('line', function (lineData) {
		if (isClose) return;
		typeof callback === "function" && callback(lineData, function () {
			isClose = true;
		});
	});
	
	// 监听读取完毕
	rl.on('close', function () {
		typeof end === "function" && end();
	});
	
	
}